package com.qingcheng.dao;

import com.qingcheng.pojo.system.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface MenuMapper extends Mapper<Menu> {
    @Select("SELECT id,name,icon,url,parent_id as parentId FROM tb_menu where id in\n" +
            "(SELECT menu_id from tb_resource_menu where resource_id in\n" +
            "\t(SELECT resource_id from tb_role_resource where role_id in \n" +
            "\t\t(SELECT role_id from tb_admin_role where admin_id =\n" +
            "\t\t\t(SELECT id from tb_admin WHERE login_name = #{loginName}\n" +
            "\t\t\t)\n" +
            "\t\t)\n" +
            "\t)\n" +
            ")\n" +
            "UNION\n" +
            "SELECT id,name,icon,url,parent_id as parentId FROM tb_menu where id in\n" +
            "(SELECT parent_id FROM tb_menu where id in\n" +
            "\t(SELECT menu_id from tb_resource_menu where resource_id in\n" +
            "\t\t(SELECT resource_id from tb_role_resource where role_id in \n" +
            "\t\t\t(SELECT role_id from tb_admin_role where admin_id =\n" +
            "\t\t\t\t(SELECT id from tb_admin WHERE login_name = #{loginName}\n" +
            "\t\t\t\t)\n" +
            "\t\t\t)\n" +
            "\t\t)\n" +
            "\t)\n" +
            ")\n" +
            "UNION\n" +
            "SELECT id,name,icon,url,parent_id as parentId FROM tb_menu where id in\n" +
            "(SELECT parent_id FROM tb_menu where id in\n" +
            "\t(SELECT parent_id FROM tb_menu where id in\n" +
            "\t\t(SELECT menu_id from tb_resource_menu where resource_id in\n" +
            "\t\t\t(SELECT resource_id from tb_role_resource where role_id in \n" +
            "\t\t\t\t(SELECT role_id from tb_admin_role where admin_id =\n" +
            "\t\t\t\t\t(SELECT id from tb_admin WHERE login_name = #{loginName}\n" +
            "\t\t\t\t\t)\n" +
            "\t\t\t\t)\n" +
            "\t\t\t)\n" +
            "\t\t)\n" +
            "\t)\n" +
            ")")
    public List<Menu> findMenusByAdmin(@Param("loginName") String loginName);

}
